<?php
// The source code packaged with this file is Free Software, Copyright (C) 2005 by
// Ricardo Galli <gallir at uib dot es>.
// It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise.
// You can get copies of the licenses here:
// 		http://www.affero.org/oagpl.html
// AFFERO GENERAL PUBLIC LICENSE is also included in the file called "COPYING".

if($_POST['urltodeal']){

	include_once('Smarty.class.php');
	$main_smarty = new Smarty;

	include('config.php');
	include(mnminclude.'link.php');
	include(mnminclude.'user.php');
	include(mnminclude.'html1.php');
	include(mnminclude.'smartyvariables.php');
	
	$link = new Link;
	$link->url = $_POST['urltodeal'];
	$link->get($_POST['urltodeal']);
	if (!$link->valid) {
		header('Content-Type: text/plain; charset=UTF-8');
		echo "badurl:";
		die;
	}
	else {
		if ($link->duplicates($link->url) > 0) {
			header('Content-Type: text/plain; charset=UTF-8');
			$link->id = $db->get_var("SELECT link_id FROM " . table_links . " WHERE link_url = '" . $link->url . "' AND link_status != 'discard'");
			$link->read();
			$firstdigger = new User();
			$firstdigger->id = $link->author;
			$firstdigger->read();
			$avatarpath = get_avatar('large', "", $firstdigger->username, $firstdigger->email);
			echo "duplicateurl:" . "由" . "<a target='_blank' href='"  . my_base_url . my_pligg_base . "/user.php?id=" . $firstdigger->id . "'>" . "<img src='" . $avatarpath ."'>" . $firstdigger->names . "</a>" . "于" . get_date($link->published_date) . "首次推荐，<a target='_blank' href='" . my_base_url . my_pligg_base . "/story.php?id=" . $link->id . "'>查看</a>" ;
			die;
		}
		else {
			if ($link->trackback == '') {
				header('Content-Type: text/plain; charset=UTF-8');
				echo "emptytrackback:";
				die;
			}
			else {
				header('Content-Type: text/plain; charset=UTF-8');
				echo "gettrackback:" . $link->trackback;
				die;
			}
		}
	}
}
?>